package com.bruce.utils.mysql;

import cn.smallbun.screw.core.Configuration;
import cn.smallbun.screw.core.engine.EngineConfig;
import cn.smallbun.screw.core.engine.EngineFileType;
import cn.smallbun.screw.core.engine.EngineTemplateType;
import cn.smallbun.screw.core.execute.DocumentationExecute;
import cn.smallbun.screw.core.process.ProcessConfig;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

import javax.sql.DataSource;
import java.util.ArrayList;

/**
 * @author luotuan
 * @Description
 * @create 2020-07-28 16:25
 **/
public class MysqlStructGenerate {
    public static void generate(){
        //数据源
        HikariConfig hikariConfig = new HikariConfig();
        hikariConfig.setDriverClassName("com.mysql.jdbc.Driver");
        hikariConfig.setJdbcUrl("jdbc:mysql://172.16.83.194:13306/oss3_dc");
        hikariConfig.setUsername("oss");
        hikariConfig.setPassword("Oss2020@123");
        //设置可以获取tables remarks信息
        hikariConfig.addDataSourceProperty("useInformationSchema", "true");
        hikariConfig.setMinimumIdle(2);
        hikariConfig.setMaximumPoolSize(5);
        DataSource dataSource = new HikariDataSource(hikariConfig);
        //生成配置
        EngineConfig engineConfig = EngineConfig.builder()
                //生成文件路径
                .fileOutputDir("F:\\software-download")
                //打开目录
                .openOutputDir(false)
                //文件类型
                .fileType(EngineFileType.WORD)
                //生成模板实现
                .produceType(EngineTemplateType.freemarker).build();

        //忽略表
        ArrayList<String> ignoreTableName = new ArrayList<>();
        ignoreTableName.add("test_user");
        ignoreTableName.add("test_group");
        //忽略表前缀
        ArrayList<String> ignorePrefix = new ArrayList<>();
        ignorePrefix.add("test_");
        //忽略表后缀
        ArrayList<String> ignoreSuffix = new ArrayList<>();
        ignoreSuffix.add("_test");
        //生成指定的表
        ArrayList<String> designatedTableList = new ArrayList<>();
        designatedTableList.add("nso_bi_requirement");
        designatedTableList.add("nso_bi_requirement_party");
        designatedTableList.add("nso_bi_requirement_product");
        designatedTableList.add("nso_sp_pst");
        designatedTableList.add("nso_sp_pst_catalog");
        designatedTableList.add("nso_sp_pst_pst_mbr_rela");
        designatedTableList.add("nso_sp_pst_mbr");
        designatedTableList.add("nso_bi_cpcp_product_pst_mbr");
        designatedTableList.add("nso_sp_pst_mbr_props");
        designatedTableList.add("nso_sp_pst_mbr_prop_enum_entity");
        designatedTableList.add("nso_bi_cpcp_product_pst_mbr_rela");
        designatedTableList.add("nso_sp_pst_mbr_event");
        designatedTableList.add("nso_bi_cpcp_msg");
        designatedTableList.add("nso_bi_cpcp_product");
        designatedTableList.add("nso_bi_cpcp_product_prop");
        designatedTableList.add("nso_bi_sop");
        ProcessConfig processConfig = ProcessConfig.builder()
                .designatedTableName(designatedTableList)
                //忽略表名
                .ignoreTableName(ignoreTableName)
                //忽略表前缀
                .ignoreTablePrefix(ignorePrefix)
                //忽略表后缀
                .ignoreTableSuffix(ignoreSuffix).build();
        //配置
        Configuration config = Configuration.builder()
                //版本
                .version("1.0.0")
                //描述
                .description("设计中心数据库设计文档")
                //数据源
                .dataSource(dataSource)
                //生成配置
                .engineConfig(engineConfig)
                //生成配置
                .produceConfig(processConfig).build();
        //执行生成
        new DocumentationExecute(config).execute();
    }

    public static void main(String[] args) {
        generate();
    }
}
